import asyncio
import aiomysql


async def execute(sql, task_id):
    print(f"{task_id}开始执行", sql)
    # 网络IO操作：连接MySql
    conn = await aiomysql.connect(host="127.0.0.1", port=3306, user="root", password="", db="mysql")
    # 网络IO操作：创建CURSOR
    print(f"{task_id}获取游标")
    cur = await conn.cursor()
    # 网络IO操作：执行SQL
    await cur.execute(sql)
    # 网络IO操作：获取SQL结果
    result = await cur.fetchall()
    print(result)
    # 网络IO操作: 关闭连接
    await cur.close()
    conn.close()
    print(f"{task_id}结束执行", sql)

tasks = [
    execute("select host,user from mysql.user", "1号"),
    execute("select * from mysql.db", "2号")
]
asyncio.run(asyncio.wait(tasks))
